<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<script>
    var quickSort = function(arr,order){
        if(arr.length <= 1){return arr};
        var pivotIndex = Math.floor(arr.length/2);
        var pivot = arr.splice(pivotIndex,1)[0];

        var left = [];
        var right = [];
        for(var i = 0; i < arr.length;i++){
            if(arr[i] > pivot){
                left.push(arr[i]);
            }else{
                right.push(arr[i]);
            }
        }

        if(order === "asc"){//升序
            return quickSort(left).concat([pivot],quickSort(right)).reverse();
        }else{//降序
            return quickSort(left).concat([pivot],quickSort(right));
        }

    };

console.log(quickSort([11,34,23,55,9,4,77,88,11,33,12,90,14],"asc"));
console.log(quickSort([11,34,23,55,9,4,77],"dsc"));
</script>

</body>
</html>